$(function(){
    // 1.加载完成后，渲染用户信息
    $.ajax({
        url:BigNew.user_detail,
        type:'get',
        dataType:'json',
        data:'',
        success: function(backData){
            console.log(backData);
            
            for(let key in backData.data){
                $(`.${key}`).val(backData.data[key])
            }
            $('.user_pic').attr('src',backData.data.userPic)
        }
    })

    //预览文件
    //1.给file表单元素注册onchange事件
    $('#exampleInputFile').change(function () {
        //1.2 获取用户选择的图片
        let file = this.files[0];
        //1.3 将文件转为src路径
        let url = URL.createObjectURL(file);
        //1.4 将url路径赋值给img标签的src
        $('.user_pic').attr('src', url);
    });

    //提交表单
    $('#form').on('submit',function(){
        $.ajax({
            url:BigNew.user_edit,
            type:'post',
            dataType:'json',
            data: new FormData(this),
            contentType: false,
            processData: false,
            success: function(backData){
                console.log(backData);
                if (backData.code == 200){
                    alert(backData.msg)
                    window.parent.location.reload()
                }else {
                    alert(backData.msg)
                }
            }
        })
        return false
    })
})